#include <reg51.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit ENLED=P1^4;
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
uint8 number[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xa7,0xa1,0x86,0x8e};
void main()
{
		uint8 counter;
		uint8 i;
		uint8 j;
		ENLED=0;ADDR3=1;
		ADDR0=1;ADDR1=0;ADDR2=1;
		TMOD=0x01;
		TF0=0;TR0=1;
		TH0=0xB8;TL0=0x00;
		counter=0;
		i=0;
		j=0;
		
		while(1)
		{
			if(1==TF0)
			{
				TF0=0;
				TH0=0xB8;TL0=0x00;
				counter++;
			}
			if(50==counter)
			{
				P0=number[i++];
				if(9==i)
				{
					i=0;
				}
				counter=0;
			}
			switch(j)
			{
				case 1:
					ADDR0=0;ADDR1=0;ADDR2=1;
					j++;
					break;
				case 2:
					ADDR0=1;ADDR1=1;ADDR2=0;
					j++;
					break;
				case 3:
					ADDR0=0;ADDR1=1;ADDR2=0;
					j++;
					break;
				case 4:
					ADDR0=1;ADDR1=0;ADDR2=0;
					j++;
					break;
				case 5:
					ADDR0=0;ADDR1=0;ADDR2=0;
					j=0;
					break;
				default:
					ADDR0=1;ADDR1=0;ADDR2=1;
					j++;
			}
	}
}